import { BasicColumn, FormSchema } from '@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import { ywDeptSelectList } from '@/api/heng/ywManage';
import { ApiSelect } from '@/components/Form';
import { useUserStore } from '@/store/modules/user';
const userStore = useUserStore();

//表格列名
export const columns: BasicColumn[] = [
  {
    title: '页面类型',
    dataIndex: 'pageType',
    format: (value) => {
      let val = '';
      if (value == 1) {
        val = '业务抽成';
      } else if (value === 2) {
        val = '迪卡侬抽成';
      }
      return val;
    },
  },
  {
    title: '部门名称',
    dataIndex: 'deptName',
  },
  {
    title: '接单组(接单+跟单)比例',
    dataIndex: 'businessGroupRate',
    width: 180,
    format: (value) => `${value ? value + '%' : ''}`,
  },
  // {
  //   title: '业务经理',
  //   dataIndex: 'manageUserName',
  // },
  {
    title: '业务经理比例',
    dataIndex: 'manageUserRate',
    width: 180,
    format: (value) => `${value ? value + '%' : ''}`,
  },
  {
    title: '项目组名称',
    dataIndex: 'xiangmuGroupName',
    width: 180,
  },
  {
    title: '项目组比例',
    dataIndex: 'xiangmuGroupRate',
    format: (value) => `${value ? value + '%' : ''}`,
    width: 180,
  },
  {
    title: '基金名称',
    dataIndex: 'jiJingName',
    width: 100,
  },
  {
    title: '基金比例',
    dataIndex: 'jiJingRate',
    format: (value) => `${value ? value + '%' : ''}`,
    width: 100,
  },
  {
    title: '创建时间',
    width: 180,
    dataIndex: 'createTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '搜索',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'pageType',
    label: '页面类型',
    required: true,
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '业务抽成',
          value: 1,
        },
        {
          label: '迪卡侬抽成',
          value: 2,
        },
      ],
    },
  },
  {
    field: 'deptName',
    label: '部门名称',
    required: true,
    slot: 'deptName',
    component: 'ApiSelect',
    componentProps: {
      resultField: 'data',
      labelField: 'deptName',
      valueField: 'deptName',
      api: ywDeptSelectList,
    },
  },
  {
    field: 'deptId',
    label: 'deptId',
    show: false,
  },
  {
    field: 'deptNo',
    label: '部门编号',
    show: false,
  },
  {
    field: 'businessGroupRate',
    label: '接单组(接单+跟单)比例',
    required: true,
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100,
      formatter: (value: number) => `${value}%`,
      parser: (value: string) => value.replace('%', ''),
    },
  },
  // {
  //   field: 'manageUserName',
  //   label: '业务经理',
  //   required: true,
  //   component: 'Input',
  // },
  {
    field: 'manageUserRate',
    label: '业务经理比例',
    required: false,
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100,
      formatter: (value: number) => `${value}%`,
      parser: (value: string) => value.replace('%', ''),
    },
  },
  {
    field: 'xiangmuGroupName',
    label: '项目组名称',
    required: false,
    component: 'Input',
    componentProps: {
      placeholder: '例:请填写“项目组”或"黄惠敏",无需填写时请放空。',
    },
  },
  {
    field: 'xiangmuGroupRate',
    label: '项目组比例',
    required: false,
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100,
      formatter: (value: number) => `${value}%`,
      parser: (value: string) => value.replace('%', ''),
    },
  },
  {
    field: 'manageUserExtra',
    label: '经理额外计算抽成',
    required: false,
    component: 'RadioGroup',
    helpMessage: '开启后不从业务组比例中扣除，直接从 订单抽成金额中扣除',
    componentProps: {
      options: [
        {
          label: '是',
          value: 1,
        },
        {
          label: '否',
          value: 0,
        },
      ],
    },
  },
  {
    field: 'jiJingName',
    label: '业务基金名称',
    required: false,
    component: 'Input',
    componentProps: {
      placeholder: '例:请填写“迪卡侬”或"OEM",无需填写时请放空。',
    },
  },
  {
    field: 'jiJingRate',
    label: '业务基金比例',
    required: false,
    component: 'InputNumber',
    suffix: '%',
    // componentProps: {
    //   min: 0,
    //   max: 100,
    //   formatter: (value: number) => `${value}%`,
    //   parser: (value: string) => value.replace('%', ''),
    // },
  },
];
